import { _decorator, Component, Node } from 'cc';
import EventManager from '../Managers/EventManager';
import { EventTypes } from '../Managers/EventTypes';
import GlobalPool from '../Tools/GlobalPool';
const { ccclass, property } = _decorator;

// 首页的游戏场景
@ccclass('GameScene')
export class GameScene extends Component {
    homeScene: Node = null;
    isShowHomeScene = false;
    protected onLoad(): void {
        EventManager.on(EventTypes.GameEvents.SetHome3dSceneEnable, this.onSetHome3dSceneEnable, this);
    }

    onSetHome3dSceneEnable(isEnable, cb?) {
        this.isShowHomeScene = isEnable;
        // 加载游戏场景
        if (!this.homeScene && isEnable) {
            EventManager.emit(EventTypes.GameEvents.LoadGameBound, () => {
                this.homeScene = GlobalPool.get('homeScene');
                this.homeScene.parent = this.node;
                this.homeScene.setPosition(0, 0, 0);
                this.homeScene.active = this.isShowHomeScene;

                cb && cb();
            })

        } else {
            this.homeScene.active = this.isShowHomeScene;
            cb && cb();
        }
    }

}


